<?php
class Lw_load {

    protected $CI;

    public function __construct()
    {
        $this->CI =& get_instance();
    }

    /**
     * @param $view
     * @param null $data
     * int VIEW_TYPE:1:完整版，2精简版：取出主题 3极简版：取出主题和快捷侧边栏
     */
    public function view($view,$data=null)
    {
        $this->CI->load->view('system/tpl/page_head',$data);
        $this->CI->load->view('system/tpl/header',$data);
        $this->CI->load->view('system/tpl/menu',$data);
        $this->CI->load->view('system/tpl/content',$data);
        $this->CI->load->view($view,$data);
        $this->CI->load->view('system/tpl/footer',$data);
        $this->CI->load->view('system/tpl/page_end',$data);
    }


    public function loginView($data=null){
        $this->CI->load->view('system/login/login',$data);
        $this->CI->load->view('system/tpl/page_end',$data);
    }

    /**
     * @param $result 结果
     * @param array $arrMsg 返回参数数组
     * @param bool $autoMsg 自动补全信息
     * @return string 返回json 数据给前端
     */
    public function jsonResult($result,$arrMsg = array(),$autoMsg=false)
    {
        $data = $arrMsg;
        if(!$autoMsg){
            if($result) {
                $data['success'] = true;
            }else{
                $data['success'] = false;
            }
            return json_encode($data);
        }
        if($result){
            $data['success'] = true;
            if(isset($data['msg'])){
                $data['msg'] .= '成功';
            }else{
                $data['msg'] = '成功';
            }
        }else{
            $data['success'] = false;
            if(isset($data['msg'])){
                $data['msg'] .= '失败';
            }else{
                $data['msg'] = '失败';
            }
        }
        return json_encode($data);
    }

}